package info.techgeek.labs.java5Features.thread.sample1;

import java.util.concurrent.*;

public class TestExe {
	
	private static int poolSize = 5;
	private static int maxPoolSize = 5;
	private static long keepAliveTime = 5;
	private static ThreadPoolExecutor threadPool = null;
	private static SynchronousQueue<Runnable> queue = null;

	public static void main(String[] args) {
//		if (args.length != 2) {
//			System.out.println("usage: java TstExecutor poolSize MaxPoolSize");
//			System.exit(1);
//		}

//		poolSize = (new Integer(args[0])).intValue();
//		maxPoolSize = (new Integer(args[1])).intValue();

		poolSize = 2;
		maxPoolSize = 9;
		
		queue = new SynchronousQueue<Runnable>();

		threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize,
				keepAliveTime, TimeUnit.SECONDS, queue);

		TestExe mte = new TestExe();

		int count = 0;
		for (count = 0; count < 10; count++) {
			Thread tThread = new TstThread(count);

			try {
				threadPool.execute(tThread);
			} catch (RejectedExecutionException re) {
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		System.out.println("Done");
	}
}
